{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from xml.dom.minidom import parse\n",
    "import xml.dom.minidom\n",
    "import pandas as pd\n",
    "import os\n",
    "#os.getcwd() #获取当前⼯作路径\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#从spell.xml中提取相关字段\n",
    "DOMTree_spell = xml.dom.minidom.parse(\"spell.xml\")\n",
    "collection_spell = DOMTree_spell.documentElement\n",
    "\n",
    "# 在集合中获取 所有spell\n",
    "spells = collection_spell.getElementsByTagName(\"spell\")\n",
    "spells_data = pd.DataFrame(columns=['id','name','type','gameautoAITarget','Zhanqi_Range','type_desc'])\n",
    "for item in spells:\n",
    "    #print( item.getAttribute(\"id\"), item.getAttribute(\"name\"), item.getAttribute(\"type\"), item.getAttribute(\"gameautoAITarget\"), item.getAttribute(\"Zhanqi_Range\"), item.getAttribute(\"type_desc\"))\n",
    "    tempdict = pd.DataFrame({'id': item.getAttribute(\"id\"), 'name': item.getAttribute(\"name\"), 'type': item.getAttribute(\"type\"),\"gameautoAITarget\":item.getAttribute(\"gameautoAITarget\"),\"Zhanqi_Range\":item.getAttribute(\"Zhanqi_Range\"), \"type_desc\":item.getAttribute(\"type_desc\")},index=[0])\n",
    "    spells_data = spells_data.append(tempdict, ignore_index=True)\n",
    "\n",
    "spells_data.to_csv(os.getcwd() + \"/spells.csv\",index=False,  encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#playcard.xml中提取相关字段\n",
    "DOMTree_card = xml.dom.minidom.parse(\"playcard.xml\")\n",
    "collection_card = DOMTree_card.documentElement\n",
    "\n",
    "# 在集合中获取 所有spell\n",
    "cards = collection_card.getElementsByTagName(\"card\")\n",
    "cards_data = pd.DataFrame(columns=['id','name','type','subType','color','number','attRange','ZhanqiRange','attDistance','defDistance','spellId','hidden','forbidTurn','send','fillinAfterSQK','moveOut'])\n",
    "for item in cards:\n",
    "    #print( item.getAttribute(\"id\"), item.getAttribute(\"name\"), item.getAttribute(\"type\"), item.getAttribute(\"gameautoAITarget\"), item.getAttribute(\"Zhanqi_Range\"), item.getAttribute(\"type_desc\"))\n",
    "    tempdict = pd.DataFrame([[item.getAttribute(\"id\"), item.getAttribute(\"name\"), item.getAttribute(\"type\"), item.getAttribute(\"subType\"), item.getAttribute(\"color\"),\n",
    "    item.getAttribute(\"number\"), item.getAttribute(\"attRange\"), item.getAttribute(\"ZhanqiRange\"), item.getAttribute(\"attDistance\"), item.getAttribute(\"defDistance\"), item.getAttribute(\"spellId\"),\n",
    "    item.getAttribute(\"hidden\"), item.getAttribute(\"forbidTurn\"), item.getAttribute(\"send\"), item.getAttribute(\"fillinAfterSQK\"), item.getAttribute(\"moveOut\")]],columns=['id','name','type','subType','color','number','attRange','ZhanqiRange','attDistance','defDistance','spellId','hidden','forbidTurn','send','fillinAfterSQK','moveOut'],index=[0])\n",
    "    cards_data = cards_data.append(tempdict, ignore_index=True)\n",
    "\n",
    "cards_data.to_csv(os.getcwd() + \"/playcard.csv\",index=False, encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#playcard.xml中提取相关字段\n",
    "DOMTree_char = xml.dom.minidom.parse(\"character.xml\")\n",
    "collection_char = DOMTree_char.documentElement\n",
    "\n",
    "# 在集合中获取 所有spell\n",
    "characters = collection_char.getElementsByTagName(\"character\")\n",
    "characters_data = pd.DataFrame(columns=['id','name','exType','country','gender','initHp','hp','class','spellId1','spellId2','spellId3','spellId4','spellId5'])\n",
    "for item in characters:\n",
    "    #print( item.getAttribute(\"id\"), item.getAttribute(\"name\"), item.getAttribute(\"type\"), item.getAttribute(\"gameautoAITarget\"), item.getAttribute(\"Zhanqi_Range\"), item.getAttribute(\"type_desc\"))\n",
    "    tempdict = pd.DataFrame([[item.getAttribute(\"id\"), item.getAttribute(\"name\"), item.getAttribute(\"exType\"), item.getAttribute(\"country\"), item.getAttribute(\"gender\"),\n",
    "    item.getAttribute(\"initHp\"), item.getAttribute(\"hp\"), item.getAttribute(\"class\"), item.getAttribute(\"spellId1\"), item.getAttribute(\"spellId2\"), item.getAttribute(\"spellId3\"),\n",
    "    item.getAttribute(\"spellId4\"), item.getAttribute(\"spellId5\")]],columns=['id','name','exType','country','gender','initHp','hp','class','spellId1','spellId2','spellId3','spellId4','spellId5'],index=[0])\n",
    "    characters_data = characters_data.append(tempdict, ignore_index=True)\n",
    "\n",
    "characters_data.to_csv(os.getcwd() + \"/characters.csv\", index=False, encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#从playcards里面提取+1马，-1马，装备牌，武器牌的id\n",
    "DOMTree_card = xml.dom.minidom.parse(\"playcard.xml\")\n",
    "collection_card = DOMTree_card.documentElement\n",
    "\n",
    "add_1_horse = []\n",
    "#-1马的id\n",
    "reduce_1_horse = []\n",
    "#装备id\n",
    "equips_list = []\n",
    "#武器id\n",
    "armss_list = []\n",
    "\n",
    "# 在集合中获取 所有spell\n",
    "cards = collection_card.getElementsByTagName(\"card\")\n",
    "for item in cards:\n",
    "    if item.getAttribute(\"type\") == 3:\n",
    "        #武器\n",
    "        if item.getAttribute(\"subType\") == 1:\n",
    "            armss_list.append(item.getAttribute(\"id\"))\n",
    "        #护甲\n",
    "        elif item.getAttribute(\"subType\") == 2:\n",
    "            equips_list.append(item.getAttribute(\"id\"))\n",
    "        #+1马\n",
    "        elif item.getAttribute(\"subType\") == 3:\n",
    "            add_1_horse.append(item.getAttribute(\"id\"))\n",
    "        #-1马\n",
    "        elif item.getAttribute(\"subType\") == 4:\n",
    "            reduce_1_horse.append(item.getAttribute(\"id\"))"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "80ec4ab0ce8367456e937475a3c6870c82c954138c5fe2d78c6a0d9dd6e4a434"
  },
  "kernelspec": {
   "display_name": "Python 3.9.12 ('tf')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
